/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package persistence;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import vo.rb_expence;

/**
 *
 * @author Shuhail
 */
public class rb_expence_persist {
    Session sess=null;
    Transaction tx=null;
    
    public static rb_expence_persist getInstance() {
        return new rb_expence_persist();
    }

    public rb_expence_persist() {
    SessionFactory sf=new Configuration().configure().buildSessionFactory();
    sess=sf.openSession();
    tx=sess.beginTransaction();
    }
    
    public boolean insert(rb_expence expence) {
        
        rb_expence exp =new rb_expence();
        
        exp.setExpence_id(expence.getExpence_id());
        exp.setExpence_name(expence.getExpence_name());
        exp.setExpence_type(expence.getExpence_type());
        
        
        sess.save(exp);
        tx.commit();
        System.out.println("Done insertion");
        return true;
    }
    
     public static void main(String[] args){
    
         rb_expence exp = new rb_expence();
         exp.setExpence_id("E003");
         exp.setExpence_name("Raw Material Purchase");
         exp.setExpence_type("Daily");
         
         rb_expence_persist rb = rb_expence_persist.getInstance();
         rb.insert(exp);
         
     }
}
